package com.pearadmin.modules.sys.controller.work;


import com.github.pagehelper.PageInfo;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import com.pearadmin.modules.sys.domain.WorkOperateAnode;
import com.pearadmin.modules.sys.service.IPoleInfoService;
import com.pearadmin.modules.sys.service.ISlotInfoService;
import com.pearadmin.modules.sys.service.ISysDeptService;
import com.pearadmin.modules.sys.service.IWorkOperateAnodeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 阳极工作信息Controller
 *
 * @author Mr.Ling
 * @date 2021-12-14
 */
@RestController
@RequestMapping("/work/operateAnode")
@Api("阳极在位工作信息")
public class WorkOperateAnodeController extends BaseController {

    private String prefix = "work/operateAnode";

    @Autowired
    private IWorkOperateAnodeService workOperateAnodeService;
    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private ISlotInfoService slotInfoService;
    @Autowired
    private IPoleInfoService poleInfoService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/work/operateAnode/main','work:operateAnode:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询阳极工作信息列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/work/operateAnode/data','work:operateAnode:data')")
    public ResultTable list(@ModelAttribute WorkOperateAnode workOperateAnode, PageDomain pageDomain) {
        PageInfo<WorkOperateAnode> pageInfo = workOperateAnodeService.selectWorkOperateAnodePage(workOperateAnode, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增阳极工作信息
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/work/operateAnode/add','work:operateAnode:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存阳极工作信息
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/work/operateAnode/add','work:operateAnode:add')")
    public Result save(@RequestBody WorkOperateAnode workOperateAnode) {
        return decide(workOperateAnodeService.insertWorkOperateAnode(workOperateAnode));
    }

    /**
     * 修改阳极工作信息
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/work/operateAnode/edit','work:operateAnode:edit')")
    public ModelAndView edit(String id, ModelMap mmap) {
        WorkOperateAnode workOperateAnode = workOperateAnodeService.selectWorkOperateAnodeById(id);
        mmap.put("workOperateAnode", workOperateAnode);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存阳极工作信息
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/work/operateAnode/edit','work:operateAnode:edit')")
    public Result update(@RequestBody WorkOperateAnode workOperateAnode) {
        return decide(workOperateAnodeService.updateWorkOperateAnode(workOperateAnode));
    }

    /**
     * 删除阳极工作信息
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/work/operateAnode/remove','work:operateAnode:remove')")
    public Result batchRemove(String ids) {
        return decide(workOperateAnodeService.deleteWorkOperateAnodeByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/work/operateAnode/remove','work:operateAnode:remove')")
    public Result remove(@PathVariable("id") String id) {
        return decide(workOperateAnodeService.deleteWorkOperateAnodeById(id));
    }
}
